/*
 * NastaveniSpodniPanel.java
 *
 * Created on 19. �erven 2007, 18:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.possoft.client.gui.panel;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.NacteniShowPanel;
import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.NastaveniShowPanel;
import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.ProhraShowPanel;
import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.RemizaShowPanel;
import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.UlozeniShowPanel;

/**
 *
 * @author mara
 */
public class NastaveniSpodniPanel extends JPanel {    
    
    private NastaveniShowPanel nastaveniShowPanel;
    private UlozeniShowPanel ulozeniShowPanel;
    private RemizaShowPanel remizaShowPanel;
    private ProhraShowPanel prohraShowPanel;
    private NacteniShowPanel nacteniShowPanel;
    
    // true pokud byl panel s remizou alespon jednou zobrazen
    private boolean remizaShownFlag = false;
    
    private static NastaveniSpodniPanel currentInstance;
    
    /** Creates a new instance of NastaveniSpodniPanel */
    public NastaveniSpodniPanel() {
        setBorder(new LineBorder(new Color(150,150,200)));
        setLayout(new BorderLayout());
        nastaveniShowPanel = null;
        ulozeniShowPanel = null;
        nacteniShowPanel = null;
        remizaShowPanel = null;
        prohraShowPanel = null;
    }
    
    public static NastaveniSpodniPanel getNastaveniSpodniPanel() {
        if (currentInstance == null) {
            currentInstance = new NastaveniSpodniPanel();
        }
        return currentInstance;
    }
    
    // UZIVATEL STISKL TLACITKO NASTAVENI, TAKZE UKAZEME nastaveniShowPanel
    public void nastaveniStisknuto() {    
        if (ulozeniShowPanel != null) ulozeniShowPanel.setVisible(false);
        if (remizaShowPanel != null) remizaShowPanel.setVisible(false);
        if (prohraShowPanel != null) prohraShowPanel.setVisible(false);
        if (nacteniShowPanel != null) nacteniShowPanel.setVisible(false);
        if (nastaveniShowPanel == null) {
            add(getNastaveniShowPanel());  
        }            
        nastaveniShowPanel.setVisible(true);                       
        validate();                
    }
    
    // UZIVATEL STISKL TLACITKO ULOZENI, TAKZE UKAZEME ulozeniShowPanel
    public void ulozeniStisknuto() {
        if (nastaveniShowPanel != null) nastaveniShowPanel.setVisible(false);
        if (remizaShowPanel != null) remizaShowPanel.setVisible(false);
        if (prohraShowPanel != null) prohraShowPanel.setVisible(false);
        if (nacteniShowPanel != null) nacteniShowPanel.setVisible(false);
        if (ulozeniShowPanel == null) {
            add(getUlozeniShowPanel());  
        }            
        ulozeniShowPanel.setVisible(true);                  
        validate();
    }
    
    // UZIVATEL STISKL TLACITKO REMIZA, TAKZE UKAZEME remizaShowPanel
    public void remizaStisknuto() {
        if (nastaveniShowPanel != null) nastaveniShowPanel.setVisible(false);
        if (ulozeniShowPanel != null) ulozeniShowPanel.setVisible(false);
        if (prohraShowPanel != null) prohraShowPanel.setVisible(false);        
        if (nacteniShowPanel != null) nacteniShowPanel.setVisible(false);
        if (remizaShowPanel == null) {
            add(getRemizaShowPanel());  
        }            
        remizaShowPanel.setVisible(true);                  
        validate();
        remizaShownFlag = true;
    }
    
    // UZIVATEL STISKL TLACITKO PROHRA, TAKZE UKAZEME prohraShowPanel
    public void prohraStisknuto() {
        if (nastaveniShowPanel != null) nastaveniShowPanel.setVisible(false);
        if (ulozeniShowPanel != null) ulozeniShowPanel.setVisible(false);
        if (remizaShowPanel != null) remizaShowPanel.setVisible(false);        
        if (nacteniShowPanel != null) nacteniShowPanel.setVisible(false);
        if (prohraShowPanel == null) {
            add(getProhraShowPanel());  
        }            
        prohraShowPanel.setVisible(true);                  
        validate();
    }        
    
    // nastava pri stisku tlacitka 'nacist hru'
    public void nacteniStisknuto() {
        if (nastaveniShowPanel != null) nastaveniShowPanel.setVisible(false);
        if (ulozeniShowPanel != null) ulozeniShowPanel.setVisible(false);
        if (remizaShowPanel != null) remizaShowPanel.setVisible(false);        
        if (prohraShowPanel != null) prohraShowPanel.setVisible(false);
        if (nacteniShowPanel == null) {
            add(getNacteniShowPanel());  
        } 
        nacteniShowPanel.refreshList();
        NacteniShowPanel.getConnectExceptionText().setText("");
        nacteniShowPanel.setVisible(true);                  
        validate();
    }
    
    // vraci nastaveniShowPanel - panel pri stisku prvniho tlacitka
    public NastaveniShowPanel getNastaveniShowPanel() {
        if (nastaveniShowPanel == null) {
            nastaveniShowPanel = new NastaveniShowPanel();
        }
        return nastaveniShowPanel;
    }
    
    // vraci ulozeniShowPanel - panel pri stisku druheho tlacitka
    public UlozeniShowPanel getUlozeniShowPanel() {
        if (ulozeniShowPanel == null) {
            ulozeniShowPanel = new UlozeniShowPanel();
        }
        return ulozeniShowPanel;
    }
    
    // vraci remizaShowPanel - panel pri stisku tlacitka 'navrhnout remizu'    
    public RemizaShowPanel getRemizaShowPanel() {
    if (remizaShowPanel == null) {
            remizaShowPanel = new RemizaShowPanel();
        }
        return remizaShowPanel;
    }
    
    // vraci prohraShowPanel - panel pri stisku tlacitka 'navrhnout remizu'    
    public ProhraShowPanel getProhraShowPanel() {
    if (prohraShowPanel == null) {
            prohraShowPanel = new ProhraShowPanel();
        }
        return prohraShowPanel;
    }
    
    // vraci nacteniShowPanel - panel pri stisku tlacitka 'naciat hru'    
    public NacteniShowPanel getNacteniShowPanel() {
    if (nacteniShowPanel == null) {
            nacteniShowPanel = new NacteniShowPanel();
        }
        return nacteniShowPanel;
    }
    
    // smaze text exception labelu, ale jen pokud byl panel uz nekdy zobrazen. Pouzito pri preruseni hry.
    public void remizaLabelFakeClean() {
       if (remizaShownFlag) {
           getRemizaShowPanel().setConnectExceptionText("");
       }
    }
    
}
